#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
通过方法操作类的属性，不会将类的属性直接暴露出来，同时还可以对属性值进行检查 加_ 将属性隐藏，只能在类内访问
通过一个set_score()方法来设置成绩，再通过一个get_score()来获取成绩，这样，在set_score()方法里，就可以检查参数
"""


class Student(object):

    def set_score(self, score):
        if score > 100 or score < 0:
            raise ValueError('score must between 0 ~ 100!')  # 抛出值错误，并自定义错误信息,程序中断
            # print('score must between 0 ~ 100!')
        if 0 <= score <= 100:
            self._score = score

    def get_score(self):
        return self._score


def main():
    s = Student()
    try:
        s.set_score(90)
        print(s.get_score())
    except ValueError:
        print('score must between 0 ~ 100!')
    print(dir(s))


if __name__ == '__main__':
    main()
